package demo04_other

object Demo03_implicitContext {

  implicit val flower: Flower = Flower()

  /**
   * 把其他的类型转换成SpecialPerson类型
   */
  implicit def transform2SpecialPerson(person:Any):SpecialPerson = {
    if(person.isInstanceOf[Student]){
      val student: Student = person.asInstanceOf[Student]
      SpecialPerson(student.name,student.role)
    }else if(person.isInstanceOf[Older]){
      val older: Older = person.asInstanceOf[Older]
      SpecialPerson(older.name,older.role)
    }else{
      null
    }
  }

}
